package com.hmkj.core.mapper.operate;

import com.hmkj.common.baseMapper.GenericMapper;
import com.hmkj.core.model.operate.QuestionsModel;
import com.hmkj.core.po.amount.AccountLog;
import com.hmkj.core.po.operate.Questions;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * 客服提问相关Dao接口<br>
 *
 * @author bin
 * @date   2017-11-30 03:04:53
 */
public interface QuestionsMapper extends GenericMapper< Questions,Integer> {

    @Select("SELECT t.*,`user`.user_name AS 'user.userName',user.mobile AS 'user.mobile',admin.name AS 'admin.name' FROM biz_questions t LEFT JOIN biz_user `user` ON `user`.id = t.user_id LEFT JOIN s_admin admin ON admin.id = t.admin_id WHERE 1=1 ${whereSql} ${sortSql} limit ${nowPage}, ${pageSize} ")
    List<QuestionsModel> findListBySqlJoin(Map<String, Object> params);

    @Select("SELECT count(1) FROM biz_questions t LEFT JOIN biz_user `user` ON `user`.id = t.user_id LEFT JOIN s_admin admin ON admin.id = t.admin_id WHERE 1=1 ${whereSql}")
    long countBySqlJoin(Map<String, Object> params);


    /**
     * 前台在线问答列表
     * @param param
     * @return
     */
    @Select("SELECT count(1) FROM biz_questions t WHERE 1=1 and t.user_id= #{userId} and t.del_flag = 1  ORDER BY t.create_time DESC")
    Integer findCountQuestionsForList(Map<String, Object> param);


    /**
     * 前台在线问答列表
     * @param param
     * @return
     */
    @Select("SELECT t.*,IFNULL(user.avatar_url,'')AS 'user.avatarUrl', user.user_name AS 'user.userName',admin.name AS 'admin.name' FROM biz_questions t  LEFT JOIN biz_user user ON user.id = t.user_id  LEFT JOIN s_admin admin ON admin.id = t.admin_id WHERE 1=1 and t.user_id= #{userId} and t.del_flag = 1 ORDER BY t.create_time DESC ")
    List<QuestionsModel> findListForQuestionsList(Map<String, Object> param);

    /**
     * 前台实时获取问题
     * @param param
     * @return
     */
    @Select("SELECT t.* FROM biz_questions t WHERE 1=1 and t.id in (${idStr}) and t.status = #{status} and t.user_id = #{userId} and t.del_flag = 1")
    List<Questions> selectListByIds(Map<String, Object> param);

    /**
     * 获取最新提问的问题
     * @param param
     * @return
     */
    @Select("SELECT t.* FROM biz_questions t WHERE 1=1 and t.question = #{question} and t.user_id = #{userId} and t.del_flag = 1 ORDER BY t.create_time DESC LIMIT 0,1")
    List<Questions> selectListByQuestions(Map<String, Object> param);

}
